home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 234_01 / zdir.c < prev   
Text File  |  1987-06-16  |  6KB  |  297 lines

  1. /*
  2.   HEADER: CUG     nnn.nn;
  3.   TITLE:     XDIR - Hard Disk Manager
  4.   VERSION:     1.0 for IBM-PC
  5.   DATE:      Apr 03, 1987
  6.   DESCRIPTION:     Hard Disk Manager for IBM PC
  7.   KEYWORDS:     Hard Disk Manager Dump Directory
  8.   SYSTEM:     IBM-PC and Compatiables
  9.   FILENAME:      zdir.c
  10.   WARNINGS:     None
  11.   CRC:         N/A
  12.   SEE-ALSO:     HDIR.DOC and XDIR.DOC
  13.   AUTHOR:     Mike Blakley 15645 SW 82 Cir Ln #76, Miami, Fl 33193
  14.   COMPILERS:     ECO-C
  15.   REFERENCES:     XDIR.DOC
  16. */
  17.  
  18.  
  19. /*
  20.    zdir.c
  21.    Superwash
  22.    to process the DOS directories
  23.  
  24. */
  25. #include "stdio.h"
  26. #include "dos.h"
  27. #include "dir.h"
  28. #include "xdir.h"
  29. extern struct tdir *pnam[];      /* directory entries */
  30. extern struct tdir *fnam[];      /* file names */
  31. extern char  cdir[];             /* current directory */
  32. extern unsigned cdate;           /* comparison date */
  33.  
  34. /*
  35.    bildir
  36.    build directory entries
  37.  
  38. */
  39. bildir()
  40. {
  41.    static DIR *dir;
  42.    struct direct *dir_entry;
  43.    char *cp;
  44.    char *calloc(int count, int size);
  45.    struct tdir *tp;
  46.    int   i;
  47.    char  workfnam[PATHSIZ];
  48.    char  workpath[PATHSIZ];
  49.    int   pcount;
  50.  
  51.  
  52.    pcount = 0;
  53.  
  54.    cp = calloc(sizeof(struct tdir),1);
  55.    if (cp == NULL) return(-1);
  56.  
  57.    tp = (struct tdir *) cp;    /* set up the first entry */
  58.    tp->d_attrib = 0x10;
  59.    tp->d_size =   0L;
  60.    pnam[pcount++] = tp;        /* priming entry */
  61.  
  62.    for (i=0;((i<pcount)&&(pcount<MAXDIR));i++)
  63.    {
  64.    tp = pnam[i];
  65.    clear(workfnam,PATHSIZ,0);
  66.    strcpy(workfnam,tp->d_path);
  67.    strcat(workfnam,"\\*.*");
  68.    clear(workpath,PATHSIZ,0);
  69.    strcpy(workpath,tp->d_path);
  70.  
  71.    dir = opendir(workfnam);     /* open directory */
  72.    setdirat(dir,0x3f);          /* was 0x10 - search all */
  73.  
  74.    while ((dir_entry = readdir(dir)) != NULL)
  75.    {
  76.    if ((dir_entry->d_attrib & 0x10) != 0x10) continue;
  77.    if (dir_entry->d_name[0] == '.') continue;
  78.    cp = calloc(sizeof(struct tdir),1);
  79.    if (cp == NULL) return(-1);
  80.    tp = (struct tdir *) cp;
  81.    strcpy(tp->d_name,dir_entry->d_name);
  82.    tp->d_attrib = dir_entry->d_attrib;
  83.    tp->d_time =   dir_entry->d_time;
  84.    tp->d_date =   dir_entry->d_date;
  85.    tp->d_size =   dir_entry->d_size;
  86.    strcpy(tp->d_path,workpath);
  87.    strcat(tp->d_path,"\\");
  88.    strcat(tp->d_path,tp->d_name);
  89.    pnam[pcount++] = tp;
  90.    if (pcount >= MAXDIR) return(MAXDIR);
  91.    }
  92.  
  93.    closedir(dir);
  94.    }
  95.    return (pcount);
  96.  
  97. }
  98.  
  99. /*
  100.    bilfil
  101.    build the file array
  102.  
  103. */
  104. int bilfil(buff,srmask,cdat,att)
  105. struct tdir *buff;
  106. char *srmask;
  107. int  cdat;
  108. int  att;
  109. {
  110.    static DIR *dir;
  111.    struct direct *dir_entry;
  112.    char *calloc(int count, int size);
  113.    struct tdir *tp;
  114.    int   fcount,i;
  115.    char  workfnam[PATHSIZ];
  116.    char  workpath[PATHSIZ];
  117.    char *cp;
  118.  
  119.    fcount = 0;
  120.  
  121.    tp = buff;                 /* get path name */
  122.    clear(workfnam,PATHSIZ,0);
  123.    strcpy(workfnam,tp->d_path);
  124.    strcpy(workpath,tp->d_path);
  125.    strcat(workfnam,"\\");
  126.    strcat(workfnam,srmask);
  127.  
  128.    dir = opendir(workfnam);     /* open directory */
  129.    setdirat(dir,0x3f);          /* search all */
  130.  
  131.    while ((dir_entry = readdir(dir)) != NULL)
  132.    {
  133.    if (dir_entry->d_attrib & 0x18) continue;
  134.    i = dir_entry->d_attrib & att;
  135.    if (att != 0)
  136.       if (i == 0) continue;
  137.    if (dir_entry->d_date < cdat) continue;
  138.    cp = calloc(sizeof(struct tdir),1);
  139.    if (cp == NULL) return(-1);
  140.    tp = (struct tdir *) cp;
  141.    strcpy(tp->d_name,dir_entry->d_name);
  142.    tp->d_attrib = dir_entry->d_attrib;
  143.    tp->d_time =   dir_entry->d_time;
  144.    tp->d_date =   dir_entry->d_date;
  145.    tp->d_size =   dir_entry->d_size;
  146.    strcpy(tp->d_path,workpath);
  147.    strcat(tp->d_path,"\\");
  148.    strcat(tp->d_path,tp->d_name);
  149.    fnam[fcount++] = tp;
  150.    if (fcount >= MAXFILE)
  151.        {
  152.        free(fnam[fcount]);
  153.        --fcount;   /* prevent overflow */
  154.        break;
  155.        }
  156.    }
  157.  
  158.    closedir(dir);
  159.  
  160.    return (fcount);
  161. }
  162. /*
  163.    dfnam
  164.    display files names
  165. */
  166. void dfnam(fcount,dirname)
  167. int fcount;
  168. char *dirname;
  169. {
  170.  
  171.    int   i,lc,c;
  172.    struct tdir *tp;
  173.    char obuff[100];
  174.    int   inter,row;
  175.    static char msg[] =
  176.         "Filename            Attr    Length Date     Time   Path";
  177.  
  178.    c = (int) dirname[0];        /* prevent compiler error */
  179.    clrscr();
  180.    boxx(79,24,1,1);
  181.    cursor(1,30);
  182.    writestr(cdir);
  183.    cursor(2,2);
  184.    writestr(msg);
  185.    inter = lc = row = 0;
  186.  
  187.    for (i=0;i<fcount;i++)    /* display the files */
  188.    {
  189.    tp = fnam[i];
  190.    dirform(tp,obuff);
  191.    cursor(row+3,2);
  192.    obuff[75] = 0;
  193.    writestr(obuff);
  194.    ++lc;
  195.    ++row;
  196.    if (lc > 20)
  197.       {
  198.       cursor(24,2);
  199.       writestr("\033[7mPress any key for next page");
  200.       writestr(" or X = cancel\033[0m ");
  201.       c = toupper(getch());
  202.       if (c == 'X') {inter=1;break;}
  203.       inter = row = 0;
  204.       clrscr();
  205.       boxx(79,24,1,1);
  206.       cursor(1,30);
  207.       writestr(cdir);
  208.       cursor(2,2);
  209.       writestr(msg);
  210.       lc = 0;
  211.       }
  212.    }
  213.  
  214.    if (inter == 0)
  215.        {
  216.        cursor(24,2);
  217.        writestr("\033[7mEnd of display - press any key\033[0m");
  218.        getch();
  219.        }
  220.    clrscr();
  221.  
  222. }
  223.  
  224. /*
  225.    compare two pointers
  226.  
  227. */
  228. pcomp(i,j)
  229. int i,j;
  230. {
  231.     int k;
  232.  
  233.     struct tdir *cpi;
  234.     struct tdir *cpj;
  235.  
  236.     cpi = pnam[i];
  237.     cpj = pnam[j];
  238.  
  239.     k = strcmp(cpi->d_path,cpj->d_path);
  240.     return (k);
  241.  
  242. }
  243.  
  244.  
  245. /*
  246.    swap two pointers
  247.  
  248. */
  249. int pswap(i,j)
  250. int i,j;
  251. {
  252.     struct tdir *cpi;
  253.  
  254.     cpi = pnam[i];
  255.     pnam[i] = pnam[j];
  256.     pnam[j] = cpi;
  257.     return (0);
  258. }
  259.  
  260.  
  261. /*
  262.    compare two pointers
  263.  
  264. */
  265. fcomp(i,j)
  266. int i,j;
  267. {
  268.     int k;
  269.  
  270.     struct tdir *cpi;
  271.     struct tdir *cpj;
  272.  
  273.     cpi = fnam[i];
  274.     cpj = fnam[j];
  275.  
  276.     k = strcmp(cpi->d_path,cpj->d_path);
  277.     return (k);
  278.  
  279. }
  280.  
  281.  
  282. /*
  283.    swap two pointers
  284.  
  285. */
  286. int fswap(i,j)
  287. int i,j;
  288. {
  289.     struct tdir *cpi;
  290.  
  291.     cpi = fnam[i];
  292.     fnam[i] = fnam[j];
  293.     fnam[j] = cpi;
  294.     return (0);
  295. }
  296.  
  297.